home *** CD-ROM | disk | FTP | other *** search
/ The Games Machine 107 / XENIATGM107.iso / Kingdom Under Fire / data1.cab / Program_Executable_Files / res / python / random.pyc (.txt) < prev    next >
Python Compiled Bytecode  |  2000-12-08  |  4KB  |  115 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 1.5)
  3.  
  4.  
  5. class whrandom:
  6.     
  7.     def __init__(self, x = 0, y = 0, z = 0):
  8.         self.seed(x, y, z)
  9.  
  10.     
  11.     def seed(self, x = 0, y = 0, z = 0):
  12.         if not None if type(y) == type(y) and type(z) == type(z) else type(z) == type(0):
  13.             raise TypeError, 'seeds must be integers'
  14.         
  15.         if not None if x <= x else None if y <= y else None if z <= z else z < 256:
  16.             raise ValueError, 'seeds must be in range(0, 256)'
  17.         
  18.         if x == x and y == y:
  19.             pass
  20.         elif y == z:
  21.             import time
  22.             t = long(time.time() * 256)
  23.             t = int(t & 16777215 ^ t >> 24)
  24.             (t, x) = divmod(t, 256)
  25.             (t, y) = divmod(t, 256)
  26.             (t, z) = divmod(t, 256)
  27.         
  28.         if not z:
  29.             pass
  30.         self._seed = (x, 1 if not x else 1, 1)
  31.  
  32.     
  33.     def random(self):
  34.         (x, y, z) = self._seed
  35.         x = 171 * x % 30269
  36.         y = 172 * y % 30307
  37.         z = 170 * z % 30323
  38.         self._seed = (x, y, z)
  39.         Val = ((x / 30269.0 + y / 30307.0 + z / 30323.0) % 1.0) * 1000
  40.         Val2 = int(Val)
  41.         if Val2 == 0:
  42.             Val2 = 1
  43.         
  44.         return Val2
  45.  
  46.     
  47.     def randomEx(self):
  48.         (x, y, z) = self._seed
  49.         x = 171 * x % 30269
  50.         y = 172 * y % 30307
  51.         z = 170 * z % 30323
  52.         self._seed = (x, y, z)
  53.         Val = ((x / 30269.0 + y / 30307.0 + z / 30323.0) % 1.0) * 1000
  54.         Val2 = int(Val)
  55.         return Val2
  56.  
  57.     
  58.     def uniform(self, a, b):
  59.         return a + (b - a) * self.random()
  60.  
  61.     
  62.     def randint(self, a, b):
  63.         return self.randrange(a, b + 1)
  64.  
  65.     
  66.     def choice(self, seq):
  67.         return seq[int(self.random() * len(seq))]
  68.  
  69.     
  70.     def randrange(self, start, stop = None, step = 1, int = int, default = None):
  71.         istart = int(start)
  72.         if istart != start:
  73.             raise ValueError, 'non-integer arg 1 for randrange()'
  74.         
  75.         if stop is default:
  76.             if istart > 0:
  77.                 return int(self.random() * istart)
  78.             
  79.             raise ValueError, 'empty range for randrange()'
  80.         
  81.         istop = int(stop)
  82.         if istop != stop:
  83.             raise ValueError, 'non-integer stop for randrange()'
  84.         
  85.         if step == 1:
  86.             if istart < istop:
  87.                 return istart + int(self.random() * (istop - istart))
  88.             
  89.             raise ValueError, 'empty range for randrange()'
  90.         
  91.         istep = int(step)
  92.         if istep != step:
  93.             raise ValueError, 'non-integer step for randrange()'
  94.         
  95.         if istep > 0:
  96.             n = ((istop - istart) + istep - 1) / istep
  97.         elif istep < 0:
  98.             n = ((istop - istart) + istep + 1) / istep
  99.         else:
  100.             raise ValueError, 'zero step for randrange()'
  101.         if n <= 0:
  102.             raise ValueError, 'empty range for randrange()'
  103.         
  104.         return istart + istep * int(self.random() * n)
  105.  
  106.  
  107. _inst = whrandom()
  108. seed = _inst.seed
  109. random = _inst.random
  110. randomEx = _inst.randomEx
  111. uniform = _inst.uniform
  112. randint = _inst.randint
  113. choice = _inst.choice
  114. randrange = _inst.randrange
  115.